/**
 * 
 */
package src;
import java.util.*;
/**
 * @author Emily
 *
 */
public class PrimHeapNode implements Comparable {

	private Double my_value;
	
	private Vertex my_vertex;
	
	private int heapPosition;
	
	private List<Vertex> knownVertices;
	
	private Edge minEdge;
	
	private boolean used;
	
	public PrimHeapNode(Vertex v) {
		my_vertex = v;
		my_value = (double) 0;
		heapPosition = 0;
		used = false;
		knownVertices = new ArrayList<Vertex>();
		
		setAdjacentList();
		setLeastEdge();
	}
	
	public Edge getLeastEdge() {
		return minEdge;
	}
	
	public void setLeastEdge() {
		Iterator itr = my_vertex.incidentEdgeList.iterator();
		minEdge = null;
		while (itr.hasNext()) {
			Edge currentEdge = (Edge) itr.next();
			if (minEdge != null) {
				if ((Double)minEdge.getData() < ((Double)currentEdge.getData()))
					minEdge = currentEdge;
				my_value = (Double) minEdge.getData();
			} else {
//				minEdge = currentEdge;
//				my_value = (Double) minEdge.getData();
			}
		}
		
		
	}

	public ArrayList<Vertex> getAdjacentVertices() {
		return (ArrayList<Vertex>) knownVertices;
	}
	
	public void setAdjacentList() {
		Iterator itr = my_vertex.incidentEdgeList.iterator();
		Edge currentEdge;
		while (itr.hasNext()) {
			currentEdge = (Edge) itr.next();
			knownVertices.add(currentEdge.getSecondEndpoint());
		}
	}
	
	public Double getValue() {
		return my_value;
	}
	
	@Override
	public int compareTo(Object arg0) {
		return (int) (my_value - ((PrimHeapNode) arg0).getValue());
	}

	public void setPosition(int i) {
		heapPosition = i;
	}
	
	public boolean isUsed() {
		return used;
	}
	
	public void setUsed() {
		used = true;
	}
}
